{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualize and Analyze Data\n",
    "\n",
    "This notebook will explore the data we downloaded in the `Customize and Access Data` notebook to fulfill the final objective of this tutorial: \n",
    "\n",
    "* Interact with ICESat-2 and MODIS data using basic Python science libraries to visualize, filter, and plot concurrent data.\n",
    "\n",
    "We will perform the following steps:\n",
    "\n",
    "1. Read in ATL07 and ATL10 data and apply time conversion\n",
    "3. Read in MOD29 data and apply scale factor \n",
    "4. Overlay ATL07 data over MOD29\n",
    "5. Extract MOD29 Ice Surface Temperature (IST) values along ATL07 height values\n",
    "6. Plot MOD29 IST and ATL07 heights\n",
    "7. Plot ATL07 and ATL10 and compare ATL10 coverage with ATL07 quality variables\n",
    "   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Import packages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import defaultdict\n",
    "import h5py\n",
    "import xarray as xr\n",
    "import pyproj\n",
    "import pandas as pd\n",
    "import pyresample as prs\n",
    "from matplotlib import pyplot as plt\n",
    "import numpy as np\n",
    "# to make sure we find the shell from ! cells\n",
    "import os\n",
    "os.environ[\"PATH\"] += os.pathsep + os.pathsep.join(['/bin', '/bin/bash'])\n",
    "\n",
    "# Helper functions\n",
    "import tutorial_helper_functions as fn\n",
    "\n",
    "#Allows plots to be rendered in notebook\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will pull the rest of our data from a staged directory. This will only be available during the in-person tutorial. \n",
    "\n",
    "Visit https://github.com/nsidc/NSIDC-Data-Tutorial for the latest tutorial developments. Use the data access notebook to get granules from NSIDC DAAC."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!aws --no-sign-request --region=YOUR-S3-REGION s3 sync s3://YOUR-S3-BUCKET/ Outputs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Read in ATL07 and ATL10 and apply time conversion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will be focusing on two packages to read in our data:\n",
    "\n",
    "* [Pandas DataFrame](https://pandas.pydata.org/pandas-docs/stable/getting_started/overview.html)\n",
    "    * Pandas is built on top of NumPy and provides easy to work with data structures. The pandas dataframe is a 2-D tabular data structure with labeled axes. \n",
    "* [Xarray](http://xarray.pydata.org/en/stable/index.html)\n",
    "    * Designed for multidimensional data. Xarray introduces labels in the form of dimensions, coordinates and attributes on top of raw NumPy-like arrays. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Load ATL07 and ATL10 granules into dataframes\n",
    "\n",
    "We will start by defining variables to extract and combine as a single dataframe:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "VARIABLES = {\n",
    "    'ATL07': [\n",
    "        '/gt1l/sea_ice_segments/delta_time',\n",
    "        '/gt1l/sea_ice_segments/latitude',\n",
    "        '/gt1l/sea_ice_segments/longitude',\n",
    "        '/gt1l/sea_ice_segments/heights/height_segment_confidence',\n",
    "        '/gt1l/sea_ice_segments/heights/height_segment_height',\n",
    "        '/gt1l/sea_ice_segments/heights/height_segment_quality',\n",
    "        '/gt1l/sea_ice_segments/heights/height_segment_surface_error_est',\n",
    "        '/gt1l/sea_ice_segments/heights/height_segment_length_seg',\n",
    "        '/gt2l/sea_ice_segments/delta_time',\n",
    "        '/gt2l/sea_ice_segments/latitude',\n",
    "        '/gt2l/sea_ice_segments/longitude',\n",
    "        '/gt2l/sea_ice_segments/heights/height_segment_confidence',\n",
    "        '/gt2l/sea_ice_segments/heights/height_segment_height',\n",
    "        '/gt2l/sea_ice_segments/heights/height_segment_quality',\n",
    "        '/gt2l/sea_ice_segments/heights/height_segment_surface_error_est',\n",
    "        '/gt2l/sea_ice_segments/heights/height_segment_length_seg',\n",
    "        '/gt3l/sea_ice_segments/delta_time',\n",
    "        '/gt3l/sea_ice_segments/latitude',\n",
    "        '/gt3l/sea_ice_segments/longitude',\n",
    "        '/gt3l/sea_ice_segments/heights/height_segment_confidence',\n",
    "        '/gt3l/sea_ice_segments/heights/height_segment_height',\n",
    "        '/gt3l/sea_ice_segments/heights/height_segment_quality',\n",
    "        '/gt3l/sea_ice_segments/heights/height_segment_surface_error_est',\n",
    "        '/gt3l/sea_ice_segments/heights/height_segment_length_seg'],\n",
    "    'ATL10': [\n",
    "        '/gt1l/freeboard_beam_segment/beam_freeboard/delta_time',\n",
    "        '/gt1l/freeboard_beam_segment/beam_freeboard/latitude',\n",
    "        '/gt1l/freeboard_beam_segment/beam_freeboard/longitude',\n",
    "        '/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence',\n",
    "        '/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag',\n",
    "        '/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height',\n",
    "        '/gt2l/freeboard_beam_segment/beam_freeboard/delta_time',\n",
    "        '/gt2l/freeboard_beam_segment/beam_freeboard/latitude',\n",
    "        '/gt2l/freeboard_beam_segment/beam_freeboard/longitude',\n",
    "        '/gt2l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence',\n",
    "        '/gt2l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag',\n",
    "        '/gt2l/freeboard_beam_segment/beam_freeboard/beam_fb_height',\n",
    "        '/gt3l/freeboard_beam_segment/beam_freeboard/delta_time',\n",
    "        '/gt3l/freeboard_beam_segment/beam_freeboard/latitude',\n",
    "        '/gt3l/freeboard_beam_segment/beam_freeboard/longitude',\n",
    "        '/gt3l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence',\n",
    "        '/gt3l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag',\n",
    "        '/gt3l/freeboard_beam_segment/beam_freeboard/beam_fb_height'\n",
    "    ]\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### We will use the `load_icesat2_as_dataframe` function from our functions module to load points from our ATL07 and ATL10 files: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load ATL07 files\n",
    "atl07_1298 = fn.load_icesat2_as_dataframe('./Outputs/processed_ATL07-01_20190323101341_12980201_002_01.h5', VARIABLES)\n",
    "atl07_1305 = fn.load_icesat2_as_dataframe('./Outputs/processed_ATL07-01_20190323211343_13050201_002_01.h5', VARIABLES)\n",
    "atl07 = pd.concat([atl07_1298,atl07_1305]) #concatenate dataframes to use in plot below\n",
    "\n",
    "# Load single ATL10 file to compare with ATL07\n",
    "atl10_1305 = fn.load_icesat2_as_dataframe('./Outputs/processed_ATL10-01_20190323211343_13050201_002_01.h5', VARIABLES)\n",
    "\n",
    "atl07_1298.head() # Print head of dataframe "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Convert ATL07 'delta_time' to utc datetime values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_granules = [atl07_1298, atl07_1305, atl10_1305] # Create list of each dataframe\n",
    "\n",
    "for df in data_granules:\n",
    "    df['utc_datetime'] = df['delta_time'].apply(fn.convert_delta_time)\n",
    "    df = df.sort_values(by=['beam', 'utc_datetime'])\n",
    "\n",
    "data_granules[0].head() # View the head of the first dataframe in list: atl07_1298"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Read in MODIS Ice Surface Temperature file and apply scale factor\n",
    "\n",
    "There were 13 granules returned over our time and area of interest. We can use Earthdata Search to easily visualize the coverage of each granule:\n",
    "[MODIS Earthdata Search result](https://search.earthdata.nasa.gov/search/granules?p=C1000001160-NSIDC_ECS&q=mod29&sb=140%2C72%2C153%2C80&m=80.14349326047419!-42.27686414753069!0!0!0!0%2C2&qt=2019-03-23T00%3A00%3A00.000Z%2C2019-03-23T23%3A59%3A59.999Z&tl=1557787959!4!)\n",
    "\n",
    "Let's choose a single MODIS granule to be used in our analysis below. \n",
    "\n",
    "Out of the 13 returned, these all have full coverage over our study area:\n",
    "\n",
    "* MOD29.A2019082.0810.006.2019082191746.hdf\n",
    "* MOD29.A2019082.0630.006.2019082191633.hdf\n",
    "* MOD29.A2019082.0455.006.2019082132032.hdf\n",
    "* MOD29.A2019082.0945.006.2019082191513.hdf\n",
    "\n",
    "And after viewing the browse images, this looks to have the best data coverage:\n",
    "\n",
    "* MOD29.A2019082.0140.006.2019082132036.hdf\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Load the MOD29 file into xarray and list variables of file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "filepath = './Outputs/MOD29_A2019082_0140_006_2019082132036_HEGOUT.hdf' # Define local filepath \n",
    "\n",
    "mod29 = xr.open_dataset(filepath)\n",
    "list(mod29.variables)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Convert calibrated data to Kelvin\n",
    "\n",
    "Before we plot the ATL07 heights over MODIS IST, we need to convert the Ice_Surface_Temperature values to kelvin. According to the [MOD29 User Guide](https://nsidc.org/data/mod29#title11) the Ice_Surface_Temperature (IST) values are stored as calibrated data. To convert to kelvin, use scale_factor = 0.01 and add_offset = 0.0 in the following equation:\n",
    "\n",
    "IST = scale_factor × (calibrated data - add_offset)\n",
    "\n",
    "The valid range for ISTs is 210 K to 313.20 K.\n",
    "\n",
    "Let's apply this conversion to our xarray:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mod29['Ice_Surface_Temperature'] = mod29['Ice_Surface_Temperature']*(0.01) # Apply calibrated data to kelvin conversion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Visualize ICESat-2 height values over MODIS Ice Surface Temperature\n",
    "\n",
    "We can visualize the ICESat-2 track locations and height values overlayed with MODIS Ice Surface Temperature. We should see higher ATL07 heights along fast ice, with lower heights over thin ice and then increasing height over drift ice. We are using the Matplotlib `pcolormesh` function to plot our MOD29 xarray as a 2D array. The ATL07 locations are plotted as a scatter plot. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.subplots(figsize=(10,5)) # set size\n",
    "plt.pcolormesh(mod29.Longitude, mod29.Latitude, mod29.Ice_Surface_Temperature, vmin=240, vmax=270, cmap='viridis') # Set range to valid IST values\n",
    "plt.colorbar(label='MOD29 IST (K)')\n",
    "plt.scatter(atl07.longitude, atl07.latitude,\n",
    "          c=atl07.height_segment_height, vmax=1.5,\n",
    "          cmap='Reds', alpha=0.6, s=1)    \n",
    "plt.colorbar(label='ATL07 Height (m)')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Extract MODIS IST values along the ICESat-2 tracks\n",
    "\n",
    "Now that we've visually inspected height and IST values, let's do some analysis. We will now extract MODIS IST values at each ATL07 point. We'll focus on the 1305 track from here on out. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Interpolating MOD29 onto ICESat-2 points\n",
    "\n",
    "To easily interpolate MOD29 to ICESat-2 points, we can use the `pyresample` library. The `radius_of_influence` parameter determines maximum radius to look for nearest neighbor interpolation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define lat lon swath geometry used for interpolation\n",
    "icesat2_geometry_atl07_1305 = prs.geometry.SwathDefinition(lons=atl07_1305['longitude'], lats=atl07_1305['latitude'])\n",
    "icesat2_geometry_atl10_1305 = prs.geometry.SwathDefinition(lons=atl10_1305['longitude'], lats=atl10_1305['latitude'])\n",
    "mod29_geometry = prs.geometry.SwathDefinition(lons=mod29['Longitude'], lats=mod29['Latitude'])\n",
    "\n",
    "# Add IST values to each pandas dataframe\n",
    "atl07_1305['mod29_ice_surface_temperature'] = prs.kd_tree.resample_nearest(mod29_geometry, mod29['Ice_Surface_Temperature'].values, icesat2_geometry_atl07_1305, radius_of_influence=1000, fill_value=np.nan)\n",
    "atl10_1305['mod29_ice_surface_temperature'] = prs.kd_tree.resample_nearest(mod29_geometry, mod29['Ice_Surface_Temperature'].values, icesat2_geometry_atl10_1305, radius_of_influence=1000, fill_value=np.nan)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can now apply nan's to the MOD29 land mask value:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "atl07_1305[atl07_1305['mod29_ice_surface_temperature'] == 50] = np.nan\n",
    "atl10_1305[atl10_1305['mod29_ice_surface_temperature'] == 50] = np.nan\n",
    "atl07_1305.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plot MODIS IST and ICESat-2 height along tracks\n",
    "\n",
    "We will use pandas plotting which utilizes matplotlib on the backend. The pandas `loc` attribute allows access to a group of rows or columns by label.\n",
    "\n",
    "The 1305 track is moving from low to high latitude: The start time begins at the fast ice, skips over an island, and moves towards warmer thin ice onto thicker drift ice. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# gt1l\n",
    "fig, ax = plt.subplots(figsize=(10,3))\n",
    "atl07_1305.loc[atl07_1305['beam'] == 'gt1l'].plot(x='latitude', y='height_segment_height', marker='.', markersize=1, linestyle='None', ax=ax)\n",
    "atl07_1305.loc[atl07_1305['beam'] == 'gt1l'].plot(x='latitude', y='mod29_ice_surface_temperature', marker='.', markersize=1, linestyle='None', ax=ax, secondary_y=True)\n",
    "fig.suptitle('ATL07-01_20190323211343_13050201_002_01.h5 gt1l')\n",
    "ax.set_ylim(-0.2,2.2)\n",
    "\n",
    "# gt2l\n",
    "fig, ax = plt.subplots(figsize=(10,3))\n",
    "atl07_1305.loc[atl07_1305['beam'] == 'gt2l'].plot(x='latitude', y='height_segment_height', marker='.', markersize=1, linestyle='None', ax=ax)\n",
    "atl07_1305.loc[atl07_1305['beam'] == 'gt2l'].plot(x='latitude', y='mod29_ice_surface_temperature', marker='.', markersize=1, linestyle='None', ax=ax, secondary_y=True)\n",
    "fig.suptitle('ATL07-01_20190323211343_13050201_002_01.h5 gt2l')\n",
    "ax.set_ylim(-0.2,2.2)\n",
    "\n",
    "# gt3l \n",
    "fig, ax = plt.subplots(figsize=(10,3))\n",
    "atl07_1305.loc[atl07_1305['beam'] == 'gt3l'].plot(x='latitude', y='height_segment_height', marker='.', markersize=1, linestyle='None', ax=ax)\n",
    "atl07_1305.loc[atl07_1305['beam'] == 'gt3l'].plot(x='latitude', y='mod29_ice_surface_temperature', marker='.', markersize=1, linestyle='None', ax=ax, secondary_y=True)\n",
    "fig.suptitle('ATL07-01_20190323211343_13050201_002_01.h5 gt3l')\n",
    "ax.set_ylim(-0.2,2.2);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Key observations:\n",
    "\n",
    "* Over fast ice (lower latitude), cold IST with fairly constant and higher ICESat-2 heights.\n",
    "* Warm IST is seen in open water, with thin ice just off the fast ice boundary.\n",
    "* As the drift ice thickens, the height is increasing as IST decreases."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "___ \n",
    "### ***On your own***: Plot ATL10 against ATL07 for a single beam. How does the coverage compare between the two?\n",
    "\n",
    "Hint: Copy the 5 lines of code for one of the ATL07 and MOD29 single beam plots above. Do not change the first ATL07 `height_segment_height` plot line. Replace the following items on the second `mod29_ice_surface_temperature` plot line:\n",
    "   1. Replace the `atl07_1305` dataframe with `atl10_1305`\n",
    "   2. Replace `mod29_ice_surface_temperature` with `beam_fb_height` as the y values\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "# Answer below!\n",
    "\n",
    "# # gt3l \n",
    "# fig, ax = plt.subplots(figsize=(10,3))\n",
    "# atl07_1305.loc[atl07_1305['beam'] == 'gt3l'].plot(x='latitude', y='height_segment_height', marker='.', markersize=1, linestyle='None', ax=ax)\n",
    "# atl10_1305.loc[atl10_1305['beam'] == 'gt3l'].plot(x='latitude', y='beam_fb_height', marker='.', markersize=1, linestyle='None', ax=ax, secondary_y=True)\n",
    "# fig.suptitle('gt3l ATL07 and ATL10 comparison')\n",
    "# ax.set_ylim(-0.2,2.2);\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Data filtering by quality flag\n",
    "\n",
    "How do the ATL07 quality parameters relate to ATL10 coverage? We should see more ATL10 values with better ATL07 quality and visa versa.\n",
    "\n",
    "The following plots show some examples of these quality flags and error estimates. You can modify plotting variable below to compare with other quality information. \n",
    "\n",
    "We will filter `height_segment_height` based on `height_segment_quality` and plot the error estimates. According to the [User Guide](https://nsidc.org/data/ATL07#title38):\n",
    "\n",
    "For ATL07 height_segment_quality: a binary indicator (1 = good, 0 = bad) of segment quality"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Available variables to plot for ATL07: \n",
    "\n",
    "# height_segment_height\n",
    "# height_segment_confidence \n",
    "# height_segment_quality\n",
    "# height_segment_surface_error_est\n",
    "# height_segment_length_seg\n",
    "\n",
    "# First Create a condition dictionary with the variables we wish to filter against. Here we want to only show the gt31 beam and good quality (quality = 1)\n",
    "cond = {\n",
    "    'beam': 'gt1l', \n",
    "    'height_segment_quality': 1\n",
    "}\n",
    "\n",
    "\n",
    "# Unfiltered ATL07 heights\n",
    "fig, ax = plt.subplots(figsize=(10,3))\n",
    "atl07_1305.loc[(atl07_1305.beam == cond['beam'])].plot(x='latitude', y='height_segment_height', marker='.', markersize=1, linestyle='None', ax=ax)\n",
    "atl07_1305.loc[(atl07_1305.beam == cond['beam'])].plot(x='latitude', y='mod29_ice_surface_temperature', marker='.', markersize=1, linestyle='None', ax=ax, secondary_y=True)\n",
    "fig.suptitle('ATL07-01_20190323211343_13050201_002_01.h5 gt1l not filtered')\n",
    "ax.set_ylim(-0.2,2);\n",
    "\n",
    "# Filtered ATL07 heights by height_segment_quality\n",
    "\n",
    "# Create list with the variables we wish to filter against\n",
    "atl07_cond = (atl07_1305.beam == cond['beam']) & (atl07_1305.height_segment_quality == cond['height_segment_quality'])\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(10,3))\n",
    "atl07_1305.loc[atl07_cond].plot(x='latitude', y='height_segment_height', marker='.', markersize=1, linestyle='None', ax=ax) # plot quality and beam condition\n",
    "atl07_1305.loc[(atl07_1305.beam == cond['beam'])].plot(x='latitude', y='mod29_ice_surface_temperature', marker='.', markersize=1, linestyle='None', ax=ax, secondary_y=True)\n",
    "plt.title('ATL07-01_20190323211343_13050201_002_01 gt1l filtered')\n",
    "ax.set_ylim(-0.2,2.2);\n",
    "\n",
    "# Filtered by quality flag and plot height estimate\n",
    "atl07_plot_var = 'height_segment_surface_error_est' # set a plot variable that can be easily modified\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(10,3))\n",
    "atl07_1305.loc[atl07_cond].plot(x='latitude', y=atl07_plot_var, marker='.', markersize=1, linestyle='None', ax=ax)\n",
    "atl07_1305.loc[(atl07_1305.beam == cond['beam'])].plot(x='latitude', y='mod29_ice_surface_temperature', marker='.', markersize=1, linestyle='None', ax=ax, secondary_y=True)\n",
    "plt.title('ATL07-01_20190323211343_13050201_002_01 gt1l error est filtered');\n",
    "\n",
    "# Plot unfiltered ATL10 heights for comparison\n",
    "fig, ax = plt.subplots(figsize=(10,3))\n",
    "atl10_1305.loc[atl10_1305.beam == cond['beam']].plot(x='latitude', y='beam_fb_height', marker='.', markersize=1, linestyle='None', ax=ax)\n",
    "atl10_1305.loc[(atl10_1305.beam == cond['beam'])].plot(x='latitude', y='mod29_ice_surface_temperature', marker='.', markersize=1, linestyle='None', ax=ax, secondary_y=True)\n",
    "plt.title('ATL10-01_20190323211343_13050201_002_01 gt1l not filtered')\n",
    "ax.set_ylim(-0.2,2.2);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What do we see above?\n",
    "\n",
    "* Height values with higher IST are getting filtered out. This is consistent with areas of more open water.\n",
    "* We can use IST to find thin ice freeboard where there is ATL07 data but no ATL10 data.  \n",
    "\n",
    "What else can you determine by plotting the other quality flags?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
